﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace TeacherHelp.FormList.Teacher
{
    public partial class StudentAchievement : BanFlashingForm
    {

        public StudentAchievement()
        {
            InitializeComponent();
        }

        private void SerachBtn_Click(object sender, EventArgs e)
        {
            string stuName = StuNameTxt.Text;
            string subjectName = SubjectsComBox.Text;
            string date = datePicker.Checked ? datePicker.Text : null;
            BLL.TestManager testManager = new BLL.TestManager();
            this.TestResultGridView.DataSource = testManager.GetTestResult(subjectName, date, Program.UserId, true, stuName);
        }

        private void ResultsForm_Load(object sender, EventArgs e)
        {
            BLL.SubjectsManager subjectsManager = new BLL.SubjectsManager();
            var subjectList = subjectsManager.GetSubejctAll();
            subjectList.Insert(0, new Model.Subjects { Name = "全部" });
            SubjectsComBox.DataSource = subjectList;
            SubjectsComBox.DisplayMember = nameof(Model.Subjects.Name);
            SubjectsComBox.ValueMember = nameof(Model.Subjects.Id);

            BLL.TestManager testManager = new BLL.TestManager();
            this.TestResultGridView.DataSource = testManager.GetTestResult(userId: Program.UserId, isTeacher: true);
        }

        private void TestResultGridView_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            var obj = TestResultGridView.Columns[e.ColumnIndex];
            if (obj.Name == "Info")
            {
                var Id = TestResultGridView.Rows[e.RowIndex].Cells[nameof(ViewModel.TestResult.Id)].Value.ToString();
                BLL.TestManager testManager = new BLL.TestManager();
                testManager.BuilderTestInfoHTML(Id);
            }

        }
    }
}
